package main

import (
	"fmt"
)

func main() {
	ch := make(chan int, 3) //存满3个元素之前,不会阻塞
	fmt.Println("len=", len(ch), "cap=", cap(ch))

	go func() {
		for i := 0; i <= 8; i++ {
			ch <- i
			fmt.Println("子go程写入i=", i)
		}
		close(ch)
	}()

	//time.Sleep(time.Second * 3)
	//for i := 0; i <= 8; i++ {
	//	num := <-ch
	//	fmt.Println("主go程读取:num=", num)
	//}
	for i:=range ch{
		fmt.Println("主go程读取:num=", i)
	}
}
